<?php

/**
 * Trace program flow
 * 
 * @param string $str Error message to print
 * @author Kirill Krasnoschekov
 */
function trace($str)
{
    if (DEBUG)
    {
        print "{$str}<br>";
    }
}

/**
 * Trace variable
 * 
 * This is a simple wrapper around var_dump()
 * 
 * @param mixed $var Variable to print
 * @param string $str Comment
 * @author Kirill Krasnoschekov
 */
function traceVar($var, $str = ">>>")
{
    static $num = 0;
    
    if ( !DEBUG )
    {
        return;
    }

    if ($str)
    {
        print "<a href=\"javascript:ToggleHidden('trace{$num}');\">
                <b>{$str}</b>
               </a><br>";
    }
    
    // Hidden by default (click to the title to expand)
    print "<pre class='trace' id=\"trace{$num}\">";
    var_dump($var);
    print "</pre>";

    $num++;
}

/**
 * Prepare the string for the storage
 * 
 * @param string $string
 * @author Kirill Krasnoschekov
 */
function prepareString($string)
{
    return htmlspecialchars($string);
}

?>